package com.servlet.project.service;

import com.servlet.project.entity.Activity;
import com.servlet.project.entity.Training;
import com.servlet.project.util.JdbcUtil;

import java.util.List;

public class TrainingService {

    /**
     * 新增
     * @param obj
     * @return
     */
    public int add(List<Object> obj) {
        String sql="insert into training(trainingdate,trainingcontent,trainingarranger) values(?,?,?) ";
        int count= JdbcUtil.executeUpdate(sql, obj);
        return count;
    }

    /**
     * 列表
     * @param page
     * @param rows
     * @param obj
     * @return
     */
    public List<Training> getListAll(int page, int rows, Training obj) {
        String sql="select * from training where 1=1 ";
        if(obj.getTrainingcontent()!=null&&!obj.getTrainingcontent().equals("")){
            sql+=" and trainingcontent like '%"+obj.getTrainingcontent()+"%' ";
        }
        sql+=" limit "+page+","+rows;
        List<Training> memberList= JdbcUtil.executeQuery(sql,null,Training.class);
        return memberList;
    }

    /**
     * 总数
     * @param obj
     * @return
     */
    public int getListCount(Training obj) {
        String sql="select * from training where 1=1 ";
        if(obj.getTrainingcontent()!=null&&!obj.getTrainingcontent().equals("")){
            sql+=" and trainingcontent like '%"+obj.getTrainingcontent()+"%' ";
        }
        List<Training> memberList= JdbcUtil.executeQuery(sql,null,Training.class);
        return memberList.size();
    }


    /**
     * 修改
     * @param objects
     * @return
     */
    public int up(List<Object> objects) {
        String sql="update training set trainingdate=?,trainingcontent=?,trainingarranger=? where trainingid=? ";
        int count= JdbcUtil.executeUpdate(sql, objects);
        return count;
    }

    /**
     * 获取
     * @param trainingid
     * @return
     */
    public Training getId(String trainingid) {
        String sql="select * from training where trainingid="+trainingid;
        List<Training> users= JdbcUtil.executeQuery(sql,null,Training.class);
        return users.get(0);
    }

    /**
     * 删除
     * @param objects
     * @return
     */
    public int del(List<Object> objects) {
        String sql="delete from training  where trainingid=? ";
        int count=JdbcUtil.executeUpdate(sql, objects);
        return count;
    }


}
